<?php
class masterbankcontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('masterbank_model');
		$this->load->library('session');
		$this->load->library('pagination_editable');
		if(($this->session->userdata('fullname') == '') || ($this->session->userdata('fullname') == NULL)){
			redirect('logincontroller');
		}
	}
	
	function index()
	{         
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('masterbankcontroller/index');
		$config['total_rows'] = $this->masterbank_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		if (isset($_POST['btnview'])) 
		{
			if($_POST['kdbankview'] == "0")
			{         
				$dataprofile = array(
					'page_title' => 'Master > Bank',
					'name' => $this->session->userdata('fullname'),
					'kodebankk' => $this->masterbank_model->getBankCode(),
					'masterbank' => $this->masterbank_model->getList($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdbankview'] == "1")
			{
				$this->masterbank_model->setKodeBank($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Master > Bank',
					'name' => $this->session->userdata('fullname'),
					'kodebankk' => $this->masterbank_model->getBankCode(),
					'masterbank' => $this->masterbank_model->getkdbanklike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdbankview'] == "2")
			{
				$this->masterbank_model->setBankname($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Master > Bank',
					'name' => $this->session->userdata('fullname'),
					'kodebankk' => $this->masterbank_model->getBankCode(),
					'masterbank' => $this->masterbank_model->getnamabanklike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
			else if($_POST['kdbankview'] == "3")
			{
				$this->masterbank_model->setnorekening($_POST['bankview']);
				$dataprofile = array(
					'page_title' => 'Master > Bank',
					'name' => $this->session->userdata('fullname'),
					'kodebankk' => $this->masterbank_model->getBankCode(),
					'masterbank' => $this->masterbank_model->getnorekeninglike(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
				);	
			}
		}
		else
		{
			$dataprofile = array(
				'page_title' => 'Master > Bank',
				'name' => $this->session->userdata('fullname'),
				'kodebankk' => $this->masterbank_model->getBankCode(),
				'masterbank' => $this->masterbank_model->getList($config['per_page'],$page),
				'links' => $this->pagination_editable->create_links(),
				'message' => ''		
			);	
		}

		$content = array(
			'content' => 'master/bank/view'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
	
    function getmasterbank() 
	{
		$idkdbank = $this->uri->segment(3);
		$this->masterbank_model->setKodeBank($idkdbank);

        $dataprofile = array(
            'page_title' => 'Master > Bank',
            'name' => $this->session->userdata('fullname'),
			'kodebankk' => $this->masterbank_model->getBankCode(),
			'masterbank' => $this->masterbank_model->getList()
            /*'individulist' => $this->Individu_model->getOneSelect(),
            'wilayahlist' => $this->Wilayah_model->getWilayahList(),
            'status_nikah' => $this->Statusnikah_model->getStatusNikahList(),
            'foto' => $this->Individu_model->get_images(),
            'role' => $this->session->userdata('role')*/
        );
        $content = array(
            'content' => 'master/bank/view'
        );
        $this->template->load('templates/default', $content, $dataprofile);
    }
	
	function tambahmasterbank() 
	{
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('masterbankcontroller/index');
		$config['total_rows'] = $this->masterbank_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
        if (isset($_POST['btnSave'])) 
		{
            if (isset($_POST['nmbank']) &&
                    isset($_POST['norek']) &&
                    isset($_POST['notlp']) &&
                    !($_POST['nmbank'] == '') &&
                    !($_POST['norek'] == '') &&
                    !($_POST['notlp'] == '')) 
			{
	            $this->masterbank_model->setBankName($_POST['nmbank']);
                $this->masterbank_model->setAddress($_POST['alamat']);
                $this->masterbank_model->setNoTelp($_POST['notlp']);
                $this->masterbank_model->setNoRekening($_POST['norek']);
                $this->masterbank_model->setCreatedBy($this->session->userdata('userid'));
			   	$tanggal=date('Y-m-d H:i:s', strtotime('now'));
				$this->masterbank_model->setCreatedOn($tanggal);
				
				$this->masterbank_model->insert();
				
                redirect('masterbankcontroller');
            } 
			else 
			{
                $dataprofile = array(
					'page_title' => 'Master > Bank',
            		'name' => $this->session->userdata('fullname'),
					'kodebankk' => $this->masterbank_model->getBankCode(),
					'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Master Bank </div>',
					'masterbank' => $this->masterbank_model->getList($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links()
                    
					/*'page_title' => 'Tambah Data Individu',
                    'name' => $this->session->userdata('name'),
                    'role' => $this->session->userdata('role'),
                    'wilayahlist' => $this->Wilayah_model->getWilayahList(),
                    'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Lengkapi Form Di Bawah Untuk Menambah Individu Jema\'at</div>',
                    'status_nikah' => $this->Statusnikah_model->getStatusNikahList()*/
                );
                $content = array(
                    'content' => 'master/bank/view'
                );
                $this->template->load('templates/default', $content, $dataprofile);
            }
        } 
		else 
		{
           $dataprofile = array(
				'page_title' => 'Master > Bank',
				'name' => $this->session->userdata('fullname'),
				'kodebankk' => $this->masterbank_model->getBankCode(),
				'masterbank' => $this->masterbank_model->getList($config['per_page'],$page),
				'links' => $this->pagination_editable->create_links(),
				'message' => ''		
			);		
			$content = array(
				'content' => 'master/bank/view'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }
	
    function ubahmasterbank() {
        $idkdbank = $this->uri->segment(3);
		$this->masterbank_model->setKodeBank($idkdbank);
		
        if (isset($_POST['btnSave'])) {
			//var_dump($this->uri->segment(3));exit;
			$this->masterbank_model->setKodeBank($_POST['kdbank']);
            $this->masterbank_model->setBankName($_POST['nmbank']);
			$this->masterbank_model->setAddress($_POST['almt']);
			$this->masterbank_model->setNoTelp($_POST['notlp']);
			$this->masterbank_model->setNoRekening($_POST['norek']);
 			$this->masterbank_model->setLastUpdateBy($this->session->userdata('userid'));
			$tanggal=date('Y-m-d H:i:s', strtotime('now'));
			$this->masterbank_model->setLastUpdateOn($tanggal);
			
            $this->masterbank_model->ubahmasterbank();

            redirect('masterbankcontroller');
        } else {
			//var_dump($_POST);exit;
            $this->masterbank_model->setKodeBank($idkdbank);
            $dataprofile = array(
			'page_title' => 'Master > Bank',
			'name' => $this->session->userdata('fullname'),
			'masterbank' => $this->masterbank_model->getkdbank()	
			);		
			$content = array(
				'content' => 'master/bank/edit'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }

    function deletemasterbank() {
        $KodeBank = $this->uri->segment(3);
        $this->masterbank_model->setKodeBank($KodeBank);
        $this->masterbank_model->deletemasterbank();
        redirect('masterbankcontroller');
    }
}